package org.examples.java.lang;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class ThreadTest {

    @Test
    public void testNewThread() throws Exception {
        Thread thread = new Thread();
        assertEquals(Thread.State.NEW, thread.getState());
        // Usually the name is Thread-999.
        assertFalse(thread.getName().equals("Thread-" + thread.getId()));
        // Default name "Thread-0" 
        assertTrue(thread.getName().startsWith("Thread-"));
        // group is inherited from parent thread 
        assertEquals(Thread.currentThread().getThreadGroup(), thread.getThreadGroup());
        // id is incremented every time thread is created 
        assertTrue(thread.getId() > 0);
        // default priority inherited from parent thread 
        assertEquals(Thread.currentThread().getPriority(), thread.getPriority());
        // default priority 
        assertEquals(5, thread.getPriority());
        // default uncaught exception handler is the group
        assertEquals(Thread.currentThread().getThreadGroup(), thread.getUncaughtExceptionHandler());
        // thread is not yet started
        assertEquals(false, thread.isAlive());
        // thread is not interrupted
        assertEquals(false, thread.isInterrupted());
        // by default thread is not daemon
        assertEquals(false, thread.isDaemon());
    }

    @Test
    public void testCurrentThread() throws Exception {
        Thread thread = Thread.currentThread();

        assertEquals(true, thread.isAlive());
    }
}
